﻿using QControlCenter.Pages;
using QControlCenter.ViewModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace QControlCenter
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : HandyControl.Controls.Window
    {
        public MainWindow()
        {
            InitializeComponent();
			this.Height = SystemParameters.MaximizedPrimaryScreenHeight *0.95;
			this.Width = SystemParameters.MaximizedPrimaryScreenWidth *0.9;
			this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
			this.DataContext = new MainWindowViewModel();
			
			

		}

		private void MouseBinding_MouseDown(object sender, MouseButtonEventArgs e)
		{
			if (e.LeftButton == MouseButtonState.Pressed)
			{
				DragMove();
			}
		}

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			Close();
		}

		private void MenuItem_Click(object sender, RoutedEventArgs e)
		{
			if(sender is MenuItem menu)
			{
				var areaName = menu.Tag.ToString();
				if (this.DataContext is MainWindowViewModel temp)
				{
					temp.AreaName = areaName;
					temp.InitData();
				}
				if (this.homepage.DataContext is HomePageViewModel homePageViewModel)
				{
					homePageViewModel.Region = areaName;
					homePageViewModel.InitData();
				}
				if (this.parameterSetting.DataContext is ParameterSettingViewModel parameterSetting)
				{
					parameterSetting.Region = areaName;
					parameterSetting.InitData();
				}
				if (this.deviceManager.DataContext is DeviceManagerViewModel deviceManagerViewModel)
				{
					deviceManagerViewModel.Region = areaName;
					deviceManagerViewModel.InitData();
				}
				if (this.agvCarPage.DataContext is AGVCarPageViewModel agvCarPageViewModel)
				{
					agvCarPageViewModel.Region = areaName;
					agvCarPageViewModel.InitData();
				}

			}
		}
	}
}